<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>管理权限</el-breadcrumb-item>
      <el-breadcrumb-item>角色列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-button type="danger" @click="btnquery">添加人员</el-button>
      <tree-table
        index-text="ID"
        show-index
        border
        :expand-type="false"
        :data="goodsList"
        :columns="treeCol"
        :selection-type="false"
      >
        <template slot="rowList" slot-scope="scope">
          <i
            class="el-icon-success"
            style="color: lightgreen"
            type="danger"
            v-if="scope.row.cat_deleted"
          ></i>
          <i class="el-icon-error" style="color: red" v-else></i>
        </template>
        <template slot="sort" slot-scope="scope">
          <el-tag v-if="scope.row.cat_level == '2'">三级</el-tag>
          <el-tag type="success" v-if="scope.row.cat_level == '0'">
            一级</el-tag
          >
          <el-tag type="warning" v-if="scope.row.cat_level == '1'">
            二级</el-tag
          >
        </template>
        <template slot="action" slot-scope="scope">
          <el-button type="success" icon="el-icon-edit">编辑</el-button>
          <el-button type="warning" icon="el-icon-delete">添加</el-button>
        </template>
      </tree-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="getList.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="getList.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <el-dialog title="人员分类" :visible.sync="dialogVisible" width="30%">
      <el-form :model="porpForm" :rules="isname" ref="porpFormRes">
        <el-form-item label="添加分类" prop="cat_name" label-width="80px">
          <el-input v-model="porpForm.cat_name"></el-input>
        </el-form-item>
        <el-form-item label="父级分类" label-width="80px">
          <el-input>
            <el-cascader
            :props='valueBinding'
              v-model="value"
              :options="parent"
              @change="handleChange"
            ></el-cascader>
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
        valueBinding:{
            
        },
        valueBinding:[],
      porpForm: {
        cat_name: "",
      },
      isname: {
        cat_name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
      },
      dialogVisible: false,
      treeCol: [
        {
          label: "分类名称",
          prop: "cat_name",
          width: "400px",
        },
        {
          label: "是否生效",
          type: "template",
          template: "rowList",
        },
        {
          label: "排序",
          type: "template",
          template: "sort",
        },
        {
          label: "操作",
          type: "template",
          template: "action",
        },
      ],
      getList: {
        type: 3,
        pagenum: 1,
        pagesize: 5,
      },
      goodsList: [],
      total: 0,
      parent: [],
    };
  },
  methods: {
    handleChange() {},
    async getaction() {
      const { data: res } = await this.$http
        .get("categories", { type: 2 })
        .catch((err) => err);
      this.parent = res.data;
    },
    btnquery() {
      this.getaction();
      this.dialogVisible = true;
    },
    handleSizeChange(newVal) {
      this.getList.pagesize = newVal;
      this.getgoodsList();
    },
    handleCurrentChange(newVal) {
      this.getList.pagenum = newVal;
      this.getgoodsList();
    },
    async getgoodsList() {
      const { data: res } = await this.$http.get("categories", {
        params: this.getList,
      });
      console.log(res);
      this.goodsList = res.data.result;
      this.total = res.data.total;
    },
  },
  mounted() {
    this.getgoodsList();
  },
};
</script>

<style lange="scss" scope>
.zk-table {
  margin: 10px 0;
}
</style>
